08. Extending RANSAC to Planes

Header Text

Extending RANSAC to Planes

Extending RANSAC to Plane

Now that you are getting the hang of RANSACing it, and understanding RANSAC for fitting a line, you can do the same thing for fitting a plane in a 3D point cloud. Your implementation will be used as part of your project, so be sure to complete the implementation in the exercise below!

If you have completed the previous exercise, you can modify your code by using the equation for a plane using three points, and the distance formula for a point to a plane.

Equation of a Plane through Three Points

Ax + By + Cz + D = 0

For

  • point1 = (x1, y1, z1)
  • point2 = (x2, y2, z2)
  • point3 = (x3, y3, z3)

Use point1 as a reference and define two vectors on the plane v1 and v2 as follows:

  • Vector v1 travels from point1 to point2 .
  • Vector v2 travels from point1 to point3
v1 = < x2 - x1, y2 - y1, z2 - z1 >
v2 = < x3 - x1, y3 - y1, z3 - z1 >

Find normal vector to the plane by taking cross product of v1 \times v2 :

v1 \times v2 = <(y2-y1)(z3-z1)-(z2-z1)(y3-y1),
(z2-z1)(x3-x1)-(x2-x1)(z3-z1),
(x2-x1)(y3-y1)-(y2-y1)(x3-x1)>

To simplify notation we can write it in the form

v1 \times v2 = < i, j, k >

then ,

i(x-x1)+j(y-y1)+k(z-z1) = 0,
ix + jy + kz -( ix1 + jy1 + kz1 ) = 0
A = i,
B = j,
C = k,
D = -( ix1 + jy1 + kz1 )

Distance between point and plane

If the plane is

Ax + By + Cz + D = 0,

then given a point (x,y,z) , the distance from the point to the plane is:
d = |A x+B y+C*z+D|/sqrt(A^2+B^2+C^2).

When implementing RANSAC, try timing how long it takes to execute and compare its time to PCL's built in RANSAC functions.

Instructions

  • In the workspace below, change line 99, to use CreateData3D
  • Once Ransac plane fitting is working well, copy the code and extend it to pointProcessor , Segment function
/ Create data
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud = CreateData3D();
  • Modify the Ransac function or create a new RansacPlane function and use the same implementation as before but now with Plane and Point formulas.

Workspace

This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity , so you may be able to download them there.

Workspace Information:

  • Default file path:
  • Workspace type: react
  • Opened files (when workspace is loaded): n/a